// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   FileServerInfo.java

package com.hfstu.file;

import com.hfstu.file.model.UploadFile;
import java.io.*;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class FileServerInfo
{

	private static FileServerInfo _instance;
	private static final String MAX_FILESIZE = "maxfilesize";
	private static final String AUTHORITY = "authority";
	private static final String FIlE_PATH = "filepath";
	private static final String MAX_TOTALSIZE = "maxtotalsize";
	private static final String DENYEXT = "denyext";
	private long maxFileSize;
	private long maxTotalSize;
	private String authority;
	private String filePath;
	private String denyext;
	private Properties allProperties;
	private Logger _log;

	public FileServerInfo()
	{
		allProperties = null;
		_log = LoggerFactory.getLogger(com/hfstu/file/FileServerInfo);
	}

	public static synchronized FileServerInfo getInstance()
	{
		if (_instance == null)
		{
			_instance = new FileServerInfo();
			_instance.init("conf-fileserver/file-server.properties");
		}
		return _instance;
	}

	public void init(String filename)
	{
		Properties serviceProps;
		InputStream inputStream;
		_log.info(System.getProperties().getProperty("java.class.path"));
		serviceProps = new Properties();
		inputStream = getClass().getClassLoader().getResourceAsStream(filename);
		if (inputStream == null)
		{
			_log.error((new StringBuilder("serviceProps file not found: ")).append(filename).toString());
			return;
		}
		try
		{
			serviceProps.load(inputStream);
			break MISSING_BLOCK_LABEL_156;
		}
		catch (IOException e1)
		{
			_log.error((new StringBuilder("serviceProps file not found: ")).append(filename).toString(), e1);
		}
		try
		{
			inputStream.close();
		}
		catch (IOException e)
		{
			_log.error(e.getMessage());
		}
		return;
		Exception exception;
		exception;
		try
		{
			inputStream.close();
		}
		catch (IOException e)
		{
			_log.error(e.getMessage());
		}
		throw exception;
		try
		{
			inputStream.close();
		}
		catch (IOException e)
		{
			_log.error(e.getMessage());
		}
		String maxFile = serviceProps.getProperty("maxfilesize");
		String maxTotal = serviceProps.getProperty("maxtotalsize");
		if (maxFile != "")
			maxFileSize = Long.parseLong(maxFile);
		if (maxTotal != "")
			maxTotalSize = Long.parseLong(maxTotal);
		authority = serviceProps.getProperty("authority");
		filePath = serviceProps.getProperty("filepath");
		denyext = serviceProps.getProperty("denyext");
		String up = StringUtils.upperCase(denyext);
		String down = StringUtils.lowerCase(denyext);
		denyext = (new StringBuilder(String.valueOf(up))).append(",").append(down).toString();
		allProperties = serviceProps;
		return;
	}

	public long getMaxFileSize()
	{
		return maxFileSize;
	}

	public long getMaxTotalSize()
	{
		return maxTotalSize;
	}

	public String getAuthority()
	{
		return authority;
	}

	public String getFilePath()
	{
		return filePath;
	}

	public String getProperty(String key)
	{
		return allProperties.getProperty(key);
	}

	public String getDenyext()
	{
		return denyext;
	}

	public String getAbsolutePath(UploadFile uploadFile)
	{
		StringBuilder sb = new StringBuilder(getFilePath());
		sb.append("/").append(uploadFile.getFileUrl());
		return sb.toString();
	}

	public File getFile(UploadFile uploadFile)
	{
		return new File(getAbsolutePath(uploadFile));
	}
}
